﻿@model Web.Models.MovieViewModel

<div style="padding: 20px;">
    
    <h1>@Model.Movie.MovieTitle</h1>

    <div>

        @if (Model != null && Model.Movie != null && Model.Movie.Files != null)
        {
                <img class="cover" src='@String.Format("http://{0}/Uploads/{1}", Request.Url.Host, Model.Movie.Files.FileUrl)' alt="cover" />
        }
        else
        {
                 <img class="cover" src='@String.Format("http://{0}/Uploads/movie_unknown.jpg", Request.Url.Host)' alt="cover" />
        }

        <div class="movieDescription" style="width: 200px;">
            <h4>Nowa czynność</h4>
        
            @if (ViewBag.IsCustomerLogged == true)
            {
                <a id="movieRentButton" class="movieButton" href='@String.Format("copies", Model.Movie.MovieGuid)' title="Wypożycz">Wypożycz</a>
                <h4>Ocena:</h4>
                <ul class="votes">
                    <li><a href="vote/1" id="vote1">Bardzo słaby</a></li>
                    <li><a href="vote/2" id="vote2">Słaby</a></li>
                    <li><a href="vote/3" id="vote3">Średni</a></li>
                    <li><a href="vote/4" id="vote4">Dobry</a></li>
                    <li><a href="vote/5" id="vote5">Bardzo dobry</a></li>
                </ul>
            }
            else
            {
                <p style="color: red; padding: 10px; text-align: justify">
                    Komentować, oceniać i wypożyczać filmy mogą jedynie zalogowani klienci. <a href='@String.Format("http://{0}/account/login", Request.Url.Host)'>Zaloguj</a> się, lub <a href='@String.Format("http://{0}/account/register", Request.Url.Host)'>zarejestruj</a> jeśli jeszcze nie posiadasz konta
                </p> 
            }

        </div>

        <div class="movieDescription">
            <h4>Statystyki</h4>
            <div class="row"><label class="headerCell" id="movieMark" style="width: 60%;">Ocena:</label><label class="contentCell" style="width: 30%;">@Model.Movie.MovieMark</label></div>
            <div class="row"><label class="headerCell" id="movieCopies" style="width: 60%;">Liczba nośników:</label><label class="contentCell" style="width: 30%;">@Model.Movie.Discs.Count</label></div>
            <div class="row"><label class="headerCell" id="movieComments" style="width: 60%;">Recencje użytkowników:</label><label class="contentCell" style="width: 30%;">@Model.Movie.Comments.Count</label></div>
            <div class="row"><label class="headerCell" id="movieVotes" style="width: 60%;">Oddanych głosów:</label><label class="contentCell" style="width: 30%;">@Model.Movie.Votes.Count</label></div>
            <div class="row"><label class="headerCell" id="movieRents" style="width: 60%;">Wypożyczeń:</label><label class="contentCell" style="width: 30%;">@Model.TotalRentsCount</label></div>
        </div>

        <div class="movieDescription">
            <h4>Informacje o filmie</h4>
            <div class="row"><label class="headerCell" id="movieDirector">Reżyser:</label><label class="contentCell">@Model.Movie.MovieDirector</label></div>
            <div class="row"><label class="headerCell" id="movieProducer">Produkcja:</label><label class="contentCell">@Model.Movie.MoviePublisher</label></div>
            <div class="row"><label class="headerCell" id="movieIssueDate">Data wydania:</label><label class="contentCell">@Model.Movie.MovieIssueDate.ToString("MMMM yyyy")</label></div>
            <div class="row"><label class="headerCell" id="movieDuration">Czas trwania:</label><label class="contentCell">@Model.Movie.MovieDuration min</label></div>
            @if (Model.SelectedKinds != null)
            {
                <div class="row">
                <label class="headerCell" id="movieKind">Gatunek:</label>
                <label class="contentCell">
                    @foreach (MovieKinds item in Model.SelectedKinds)
                    {
                        <label>@item.MovieKindName</label>
                    }
                </label>
                </div>
            }
        </div>

    </div>

    <div style="clear:both; margin: 20px; border-top: solid 1px silver; padding-top: 20px;"></div>
    
    @if (ViewBag.IsCustomerLogged == true || ViewBag.IsAdminLogged == true)
    {
        <div style="overflow: hidden; width: 40%; float: left;">
            @using (Html.BeginForm())
            {
                <div class="form" style="width: 90%">
                    <div class="formtitle">Komentarz</div>
                        <div class="input nobottomborder">
				            <div class="inputtext">Treść komentarza:</div>
				            <div class="inputcontent">
					            @Html.TextAreaFor(x => x.NewComment)
				            </div>
			            </div>			

			            <div class="buttons">
				            <input class="orangebutton" type="submit" value="Dodaj" />
				            <input class="greybutton" type="submit" value="Wyczyść" />
			            </div>
                </div>
            }
        
            @if (Model.LastVotes != null && Model.LastVotes.Count > 0)
            {
                <div style="width: 300px;">
                <h4>Ostatnie głosowania:</h4>
                <table>
                        @foreach (Votes vote in Model.LastVotes)
                        {
                            <tr>
                                <th>@vote.Users.UserDisplayName</th>
                                
                                    @if (vote.VoteMark == 1)
                                    {<td><img src="../../Content/images/icons/starBlack.png" alt="1" /></td>}
                                    else if (vote.VoteMark == 2)
                                    {<td><img src="../../Content/images/icons/starBlue.png" alt="2" /></td>}
                                    else if (vote.VoteMark == 3)
                                    {<td><img src="../../Content/images/icons/starGreen.png" alt="3" /></td>}
                                    else if (vote.VoteMark == 4)
                                    {<td><img src="../../Content/images/icons/starSilver.png" alt="4" /></td>}
                                    else if (vote.VoteMark == 5)
                                    {<td><img src="../../Content/images/icons/starYellow.png" alt="5" /></td>}                                                                                                     
                            </tr>
                        }
                </table>
            </div>
            }

        </div>
        
        <div style="overflow: hidden; width: 55%; float: left; margin-left: 20px;">
            
                @if (Model.Comments != null)
                {
                    foreach (Comments comment in Model.Comments)
                    {
                    
                        <div class="form" style="width: 100%">
                            <div class="formtitle">
                                Autor: @comment.Users.UserDisplayName
                                <div style="float:right;margin-right: 30px;"> @comment.CommentDateTime.ToString("d MMMM yyyy")</div>
                            </div>
                                <div class="input nobottomborder">
				                    
				                    <div class="inputcontent">
					                    @comment.CommentText
				                    </div>
                                    @if (ViewBag.CurrentUserGuid == @comment.UserGuid || ViewBag.IsAdminLogged)
                                    {
                                        <a href='@String.Format("comments/{0}/delete",@comment.CommentGuid)' style="float: right;">Usuń</a>
                                    }
			                    </div>			
                        </div>
                    }
                }

                <div class="pagesNavigation">
                    @Html.PageLinks(Model.CommentsPagingInfo, x => Url.Action("Details", new { page = x }))
                </div>

        </div>
    }
    else
    {
        <h4>Dostęp do komentarzy mają jedynie zalogowani użytkownicy!</h4>
    }
    

</div>